package com.outsource.framework.util.common.seriallizer;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

public class CustomDateDeSerializer extends JsonDeserializer<Date> {

	@Override
	public Date deserialize(JsonParser arg0, DeserializationContext arg1)
			throws IOException, JsonProcessingException {
		// TODO Auto-generated method stub
		SimpleDateFormat  sdfy = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try{  
            String fieldData= arg0.getText();  
            return sdfy.parse(fieldData);  
        }catch (Exception e) {  
            Calendar ca= Calendar.getInstance();  
            ca.set(1970, Calendar.JANUARY, 1, 0, 0, 0);  
            return ca.getTime();  
        }  
	}

}
